package hn.cch.plugin.runner;

import hn.cch.plugin.entity.RecordEntity;
import hn.cch.plugin.plugin.RecordPlugin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.plugin.core.PluginRegistry;
import org.springframework.plugin.core.config.EnablePluginRegistries;
import org.springframework.stereotype.Component;

@EnablePluginRegistries(value = RecordPlugin.class)
@Component
public class PluginRunner implements ApplicationRunner {

    // @Autowired
    // private RecordPlugin recordPlugin;
    @Autowired
    private PluginRegistry<RecordPlugin, RecordEntity> pluginRegistry;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        RecordEntity recordEntity = new RecordEntity();
        recordEntity.setEnable(true);
        recordEntity.setAmount(1.25);
        for (RecordPlugin recordPlugin : pluginRegistry.getPlugins()) {
            recordPlugin.updateRecord(recordEntity);
        }

    }
}
